package com.TT.controller;

import org.joda.time.DateTimeFieldType;
import org.joda.time.LocalDate;
import org.junit.Test;

import java.util.Date;

/**
 * @author 苏文广 created at 2018/12/6
 * @Description:
 */

public class Simple {
    @Test
    public void testTime() throws InterruptedException {
        Date now = new Date();
        long time = now.getTime();
        System.out.println(time);
//                Thread.sleep(5000);
        Date then = new Date();
        long time1 = then.getTime();
        long l = time1 - time;
        System.out.println("相距：" + l);
        //date.getTime()是毫秒


       timestamtpToInt(now);
    }

    /**
     * 把timestamp 转化为20181209整型
     *
     * @param now
     *
     * @return
     */
    public int timestamtpToInt(Date now) {
        int date = now.getDate();
        int year = now.getYear() + 1900;
        int month = now.getMonth() + 1;

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(year).append(month);
        if (date <= 9 && date > 0) {
            stringBuilder.append(0).append(date);
        } else {
            stringBuilder.append(date);
        }
        String x = stringBuilder.toString();
        return Integer.valueOf(x);
    }
    @Test
    public void testC(){
        LocalDate localDate =new LocalDate();
        System.out.println(localDate);
        LocalDate localDate1 = localDate.plusDays(-1);
        System.out.println(localDate1);

        System.out.println(localDate.dayOfWeek());
        System.out.println(localDate.dayOfYear());
        System.out.println(localDate.get(DateTimeFieldType.dayOfYear())+

                "---"+localDate.get(DateTimeFieldType.dayOfMonth())+
                "---"+localDate.get(DateTimeFieldType.dayOfWeek()));

    }
}
